<?php
require(dirname(__FILE__)."/../inc/common.inc.php");
admin(4);
?>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<!--[if lt IE 9]>
<script type="text/javascript" src="js/html5.js"></script>
<script type="text/javascript" src="js/respond.min.js"></script>
<script type="text/javascript" src="js/PIE_IE678.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="css/H-ui.css"/>
<link type="text/css" rel="stylesheet" href="css/H-ui.admin.css"/>
<link type="text/css" rel="stylesheet" href="font/font-awesome.min.css"/>
<!--[if IE 7]>
<link href="font/font-awesome-ie7.min.css" rel="stylesheet" type="text/css" />
<![endif]-->
<title>分类管理</title>
</head>
<body>
<?php
if ($action=="add"){
	if ($subit)
	{
	print_r($_POST);
		if (!empty($s_id))//修改
		{
			if ($sid==$m_fid){
					refreshto('menu.php?action=add&sid='.$sid,'修改失败!',3);
			}			
			$query = $db->query("update {$pre}menu set m_title='".filtrate($m_title)."',m_fid=".filtrate($m_fid).",m_url='".filtrate($m_url)."' where m_id=".$s_id);
			logo('修改菜单');
			refreshto(($backurl?base64_decode($backurl):'?'),'修改成功!',2);
		}
		else//添加
		{
				$query = $db->query("INSERT INTO {$pre}menu (m_title,m_fid,m_url) VALUES ('".filtrate($m_title)."',$m_fid,'".filtrate($m_url)."')");
				logo('添加菜单');				
				refreshto(($backurl?base64_decode($backurl):'?'),'添加成功!',2);
		}
	}
	
	if ($s_id)
	{
		$query = $db->query("select * from {$pre}menu where m_id=".$s_id);
		while($rs = $db->fetch_array($query)){	
			$stitle=$rs['m_title'];
			$sfid=$rs['m_fid'];
			$murl=$rs['m_url'];
		}
	}
?>

<div class="pd-20">
  <div class="Huiform">
   <form method="post" name="form1" target="_parent" >
       <input type="hidden" name="backurl" value="<?=$backurl?>">
      <table class="table table-bg">
        <tbody>
          <tr>
	  <td height="20" align="right" bgcolor="#FFFFFF" class="tdbg">导航名称：</td>
	  <td height="20" bgcolor="#FFFFFF" class="tdbg"><input name="m_title" class="input-text" value="<?=$stitle?>" /></td>
  </tr>	
	<tr>
		<td width="17%" height="20" align="right" bgcolor="#FFFFFF" class="tdbg">上级类别：</td>
    <td width="83%" height="20" bgcolor="#FFFFFF" class="tdbg">
      <select name="m_fid" class="select">
			<option value="0" >一级分类</option>
		<?php
		$query = $db->query("select * from {$pre}menu where m_fid=0");
		while($rs = $db->fetch_array($query)){	
		if (!empty($sfid))
		{
			if ($sfid==$rs['m_id'])
			{
				$selected="selected";
			}
			else
			{
				$selected='';
			}
		}
		if ($addid==$rs['m_id'])
		{
			$selected1="selected";
		}
		else
		{
			$selected1='';
		}
			
		
			echo "<option value=\"".$rs['m_id']."\" {$selected} {$selected1}>".$rs['m_title']."</option>";
		}
		?>
		  </select><input type="hidden" value="<?=$sid?>" name="sid" />		</td>
	</tr>
    <tr>
	  <td height="20" align="right" bgcolor="#FFFFFF" class="tdbg">连接地址：</td>
	  <td height="20" bgcolor="#FFFFFF" class="tdbg"><input type="text" class="input-text" name="m_url" value="<?=$murl?>">(如果为一级分类,请留空)</td>
    </tr>
	
          <tr>
            <th></th>
            <td><button class="btn btn-success radius" type="submit" name="subit" value="Ok"><i class="icon-ok"></i> 确定</button></td>
          </tr>
        </tbody>
      </table>
    </form>
  </div>
</div>



<?php
}else{
?>
<nav class="Hui-breadcrumb"><?=get_category(4)?> <a class="btn btn-success radius r mr-20" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="icon-refresh"></i></a></nav>
<div class="pd-20 text-c">
  <button type="button" class="btn btn-success" id="d" name="byer"  onClick="article_class_edit('0','620','260','分类编辑','?action=add&s_id=&backurl=<?=base64_encode($WEBURL)?>')" ><i class="icon-plus"></i> 添加</button>
  
  <div class="article-class-list cl mt-20">
    <table class="table table-border table-bordered table-hover table-bg">
    <form method="post" name="faoe">
      <thead>
        <tr class="text-c">
          <th width="80">ID</th>
          <th width="80">排序</th>
          <th>分类名称</th>
          <th width="70">操作</th>
        </tr>
      </thead>
      <tbody>
      
      <?php
if ($del)
	{
			$query = $db->query("delete from {$pre}menu where m_id=".$s_id);
			$query = $db->query("delete from {$pre}menu where m_fid=".$s_id);
			logo('删除菜单');
			refreshto($FROMURL,'删除成功!',2);
	}
	if($sund){
		$query = $db->query("select * from {$pre}menu order by m_id asc");
		while($rs = $db->fetch_array($query)){	
			$b='m_int'.$rs['m_id'];
			$cc=$$b;
			
			$db->query("update {$pre}menu set m_int='{$cc}' where m_id='".$rs['m_id']."'");
		}
		logo('修改菜单排序');
		refreshto($FROMURL,'修改成功!',2);
		
	}	  
$query = $db->query("select * from {$pre}menu where m_fid='0' ORDER BY m_int asc");
while($rs = $db->fetch_array($query)){		
?>
      
      
        <tr class="text-c">
          <td><?=$rs['m_id']?></td>
          <td><input type="text" class="input-text" style="width: 60px;" size="5" name="m_int<?=$rs['m_id']?>" value="<?=$rs['m_int']?>"></td>
          <td class="text-l"><?=$rs['m_title']?></td>
          <td class="f-14"><a title="编辑" href="javascript:;" onClick="article_class_edit('<?=$rs['m_id']?>','620','260','分类编辑','?action=add&s_id=<?=$rs['m_id']?>&backurl=<?=base64_encode($WEBURL)?>')" style="text-decoration:none"><i class="icon-edit"></i></a> <a title="删除" href="?del=del&s_id=<?=$rs['m_id']?>" onClick="if(confirm('是否真的要删除本信息')){location.href=''+this.href};return false;" class="ml-5" style="text-decoration:none"><i class="icon-trash"></i></a></td>
        </tr>
        	<?php
          	$query1 = $db->query("select * from {$pre}menu where m_fid=".$rs['m_id']." order by m_int asc");
while($irs = $db->fetch_array($query1)){	
        ?>
        <tr class="text-c">
          <td><?=$irs['m_id']?></td>
          <td>&nbsp;&nbsp;<input class="input-text" style="width: 50px;"  type="text" size="4" name="m_int<?=$irs['m_id']?>" value="<?=$irs['m_int']?>"></td>
          <td class="text-l">&nbsp;&nbsp;├&nbsp;<?=$irs['m_title']?></td>
          <td class="f-14"><a title="编辑" href="javascript:;" onClick="article_class_edit('<?=$irs['m_id']?>','620','260','分类编辑','?action=add&s_id=<?=$irs['m_id']?>&backurl=<?=base64_encode($WEBURL)?>')" style="text-decoration:none"><i class="icon-edit"></i></a> <a title="删除" href="?del=del&s_id=<?=$irs['m_id']?>" onClick="if(confirm('是否真的要删除本信息')){location.href=''+this.href};return false;" class="ml-5" style="text-decoration:none"><i class="icon-trash"></i></a></td>
        </tr>
     <?php
     }
	 ?>
        
        <?php
        }
        ?>
        <tr class="text-c">
          <td colspan="4"><input type="submit" value="修改排序" class="btn btn-success radius" name="sund"></td>
        </tr>
        
      </tbody>
      </form>
    </table>
  </div>
</div>
<?php
}
?>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/Validform_v5.3.2_min.js"></script> 
<script type="text/javascript" src="layer/layer.min.js"></script>
<script type="text/javascript" src="js/H-ui.js"></script>
<script type="text/javascript" src="js/H-ui.admin.js"></script>
<script type="text/javascript">
$(".Huiform").Validform(); 
</script>
</body>
</html>